package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.GoodsPrice;
import com.xinhe.web.request.GoodsPriceModel;
import com.xinhe.web.service.GoodsPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(value = "商品规格", tags = {"商品规格"})
@RestController
@RequestMapping(value = {"/goodsPrice"}, produces = {"application/json;charset=UTF-8"})

public class GoodsPriceController {
    @Autowired
    private GoodsPriceService goodsPriceService;

    @ApiOperation("商品价格/规格详情")
    @PostMapping({"/findGoodsPrice"})
    public Result findGoodsPrice(Long goodsId) {
        return this.goodsPriceService.findGoodsPrice(goodsId);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询商品规格")
    @RequestMapping({"/pageGoodsPrice"})
    public QueryResults<GoodsPrice> pageGoodsPrice(Long goodsId, String name, int pageNum, int pageSize) {
        return this.goodsPriceService.pageGoodsPrice(goodsId,name,pageNum,pageSize);
    }
    @ApiOperation(httpMethod = "POST", value = "保存商品规格")
    @RequestMapping({"/saveGoodsPrice"})
    public Result saveGoodsPrice(@Valid GoodsPriceModel model) {
        return this.goodsPriceService.saveModel(model);
    }
    @ApiOperation(httpMethod = "GET", value = "删除商品规格")
    @ApiImplicitParam(name = "goodsPriceId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteGoodsPrice"})
    public Result deleteGoodsPrice(Long goodsPriceId) {
        return this.goodsPriceService.delete(goodsPriceId);
    }
    @ApiOperation(httpMethod = "GET", value = "商品规格详情")
    @ApiImplicitParam(name = "goodsPriceId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailGoodsPrice"})
    public Result detailGoodsPrice(Long goodsPriceId) {
        return this.goodsPriceService.findById(goodsPriceId);
    }

}
